const fs = require("fs");

function readFile(path, prevData) {
  return new Promise((resolve, reject) => {
    fs.readFile(path, "utf8", function (err, data) {
      if (err) {
        reject(err);
      }
      // reject("发生错误了");
      const resData = JSON.parse(data);
      resolve({
        prevData,
        resData,
      });
    });
  });
}

readFile("./data/user.json")
  .then((res) => {
    const { resData } = res;
    return readFile("./data/userCourse.json", resData);
  })
  .then(
    (res) => {
      const { prevData, resData } = res;
      console.log(prevData);
      console.log(resData);
    },
    (err) => {
      console.log("then" + err);
    }
  )
  .then((res) => {
    console.log(res);
  })
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.log("catch" + err);
  });
